package org.anyin.gitee.cloud.center.auth.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.anyin.gitee.cloud.center.auth.extension.LoginHandler;
import org.anyin.gitee.cloud.center.auth.extension.dto.LoginUserDTO;
import org.anyin.gitee.cloud.center.auth.service.LoginService;
import org.anyin.gitee.cloud.center.auth.service.dto.LoginDTO;
import org.anyin.gitee.cloud.center.upms.api.resp.SysUserResp;
import org.anyin.gitee.cloud.lib.core.extension.IExtensionHandlerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class LoginServiceImpl implements LoginService {

    @Autowired
    private IExtensionHandlerFactory extensionHandlerFactory;

    @Override
    public LoginUserDTO login(LoginDTO param) {
        LoginHandler handler = extensionHandlerFactory.getExtensionHandler(param.getType(), LoginHandler.class);
        switch (param.getType()) {
            case MOBILE:
                return handler.login(param.getMobile(), param.getCode());
            case USERNAME:
                return handler.login(param.getUsername(), param.getPassword());
            case EMAIL:
                return handler.login(param.getEmail(), param.getPassword());
        }
        return null;
    }
}
